const fs = require('fs');
exports.getImage = function (params) {
    return new Promise(function (resolve, reject) {
        weChatApi.getMedia(params.media_id, function (err, result, response) {
            console.log("result=====>", result);
            console.log("response=====>", response);
            if (err) {
                reject(err)
            } else {
                let fileName = '/imageCache/' + response.headers['content-disposition'].match(/={0}\w*.(jpg|png|gif|jpeg)/g)[0];
                console.log(config.project_dir + "/public" + fileName);
                fs.writeFile(config.project_dir + "/public" + fileName, result, function (err) {
                    if (err) {
                        reject(err)
                    } else {
                        resolve(fileName);
                    }
                });
            }
        })
    });
};
